clear all
set more off

use "WB_trade_climate_merged.dta", clear

xtset iso year
local weighting ag_pop /*none*/

gen merch_import_share = merchandise_imports/GDP
gen merch_export_share = merchandise_exports/GDP
gen logGDP = ln(GDP)
order merch_import_share-logGDP, after(population)
replace gdd = gdd/100
replace kdd = kdd/100
replace growingseason_gdd = growingseason_gdd/100
replace growingseason_kdd = growingseason_kdd/100
replace GDP = GDP/1000000000
gen ag_pop = ag_labor_share*population

label var merch_import_share "Import Share"
label var merch_export_share "Export Share"
label var food_share_imports "Food Share"
label var ag_share_GDP "Ag Share"
label var ag_labor_share "Ag Labor Share"
label var GDP "GDP"
label var gdd "GDD X 100"
label var kdd "KDD X 100"
label var logGDP "log(GDP)"
label var growingseason_gdd "Growing Season GDD X 100"
label var growingseason_kdd "Growing Season KDD X 100"
local clustering_types `""vce(un, kiefer)" "vce(cluster iso)" "vce(cluster iso year)""'

gen ag_pop_alt = ag_share_GDP*population

xtset iso year
local outcomes_vars food_share_imports ag_share_GDP ag_labor_share GDP logGDP

if "`weighting'" == "ag_pop" {
foreach v of local outcomes_vars {
xtscc `v' kdd gdd i.iso i.year [aw=ag_pop], fe lag(5)
estimates store reg_`v'
}

esttab reg_logGDP reg_food_share_imports reg_ag_share_GDP reg_ag_labor_share ///
using "cross_country_regs_agpop.tex", keep(gdd kdd) replace noconstant nostar label booktabs width(0.9\hsize) 

}

if "`weighting'" == "none" {
foreach v of local outcomes_vars {
xtscc `v' kdd gdd i.iso i.year, fe lag(5)
estimates store reg_`v'

esttab reg_logGDP reg_food_share_imports reg_ag_share_GDP reg_ag_labor_share ///
using "cross_country_regs_unweighted.tex", keep(gdd kdd)replace noconstant nostar label booktabs width(0.9\hsize) 
}
}

